<?php
namespace jy_yuejie;
defined('BY_JYA') or exit('error');
/*
*/
class member extends \plugin{
	/*
		申请
	*/
	public function apply_agent($mid=0){
		$mid=$mid?:$_SESSION['uid'];
		$member=pdo_get('jy_weishop_member',array('mid'=>$mid,'merchid'=>0,'uniacid'=>$_SESSION['uniacid']));
		//if(!$this->setting['become_check']){
			$this->check_apply($member,1);
		//}
		return true;
	}
	/*
		审核师傅
	*/
	public function check_apply($member=array(),$status,$remark=''){
		if(!$member || !$status){
			return;
		}
		$member['yuejie_endtime']=$member['yuejie_endtime']?:time();
		$member_update=array(
				'level'=>$this->setting['shoplevel_id'],
				'yuejie_type'=>$this->setting['become_check']?4:1,
				'yuejie_endtime'=>$member['yuejie_endtime']+365*24*3600
		);
		if($member['yuejie_type']==1){
			pdo_update('jy_weishop_member',$member_update,array('id'=>$member['id'],'merchid'=>0,'uniacid'=>$_SESSION['uniacid']));
			$this->model('notice')->notice_check_apply($member);
		}else{
			pdo_update('jy_weishop_member',$member_update,array('id'=>$member['id'],'merchid'=>0,'uniacid'=>$_SESSION['uniacid']));
		}
		$this->model('member')->checkinlog($member['mid']);
		return true;
	}
	/*
		禁用师傅
	*/
	public function stop_agent($agent_id){
		pdo_update('jy_weishop_member',array('stop'=>1),array('merchid'=>0,'mid'=>$agent_id));
	}
	/*
		恢复师傅
	*/
	public function start_agent($agent_id){
		pdo_update('jy_weishop_member',array('stop'=>0),array('merchid'=>0,'mid'=>$agent_id));
	}
	public function checkinlog($mid=0){
		$mid=$mid?:$_SESSION['uid'];
		$isinlog=pdo_get('jy_yuejie_inlog',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
		if($isinlog['id']){
			return false;
		}else{
			$member=pdo_get('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid,'merchid'=>0));
			if($member['yuejie_type']){
				$data=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$mid,
					'yuejie_type'=>$member['yuejie_type'],
					'createtime'=>TIMESTAMP,
				);
				$this->insert('inlog',$data);
				return false;
			}else{
				return true;
			}
		}
	}
	public function upinlog($yuejie_type=0){
		$isinlog=pdo_get('jy_yuejie_inlog',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		if($isinlog['id']){
			return false;
		}
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'yuejie_type'=>$yuejie_type,
			'createtime'=>TIMESTAMP,
		);
		$this->insert('inlog',$data);
		return true;
	}
}